import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-03-25
 * Time: 15:09
 */
public class test2 {
    public static void main(String[] args) {
        Scanner q=new Scanner(System.in);
        while (q.hasNext()){
            int m=0;
            int max=0;
            int count=0;
            int mi0=0;
        int n=q.nextInt();


            for (int i = 0; i < n; i++) {
                int b=q.nextInt();
                if(b<0){
                    count++;
                    if(b<mi0){
                        mi0=b;
                    }
                }
                m+=b;
                if(m>max){
                    max=m;
                }
                if(m<=0){
                    m=0;
                }
            }
            if(count==n){
                System.out.println(mi0);
            }else
            System.out.println(max);
        }
    }
}
